package com.yneusoft.manage.controller;

import com.yneusoft.common.model.ResponseWrapper;
import com.yneusoft.manage.model.param.*;
import com.yneusoft.manage.service.BookManageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;


/**
 * @author lt
 * @date 2021/10/20 19:05
 * @description:
 */
@RestController
public class BookManageController {
    @Autowired
    private BookManageService bookManageService;

    /**
     * 1.获取图书类型
     *
     * @return aid 图书aid，name 图书类型名称
     */
    @GetMapping("/bookManage/getBookType")
    public ResponseWrapper getBookType() {
        return bookManageService.getBookType();
    }

    /**
     * 2.获取图书列表
     *
     * @param param GetBookListParam类
     * @return rowNumber 总记录数，totalNumber 图书总数，aid 图书aid，isbn isbn号，typeName 图书类型名称，name 图书名，quantity 图书数量，createTime  新增日期
     */
    @GetMapping("/bookManage/getBookList")
    public ResponseWrapper getBookList(@Validated SearchBookParam param) {
        return bookManageService.getBookList(param);
    }

    /**
     * 3.根据id删除图书
     *
     * @param param DeleteBookParam类
     */
    @PostMapping("/bookManage/delBook")
    public ResponseWrapper delBook(@RequestBody @Validated DeleteBookParam param) {
        return bookManageService.delBook(param);
    }

    /**
     * 4.校验损坏数量
     *
     * @param param CheckDamageBookQuantityParam类
     * @return isExist true：超额，false:未超额
     */
    @GetMapping("/bookManage/checkDamageNumber")
    public ResponseWrapper checkDamageBook(@Validated CheckDamageBookQuantityParam param) {
        return bookManageService.checkDamageBook(param);
    }

    /**
     * 5.提交损坏图书
     *
     * @param param DamageBookCommitParam类
     * @return ResponseWrapper更新的结果
     * @author: wb
     */
    @PostMapping("/bookManage/damageBook")
    public ResponseWrapper damageBook(@RequestBody @Validated DemageBookParam param) {
        return bookManageService.damageBook(param);
    }

    /**
     * 6.获取图书修改信息
     *
     * @param aid 图书aid
     * @return getBookInfoResult
     */
    @GetMapping("/bookManage/getBookInfo")
    public ResponseWrapper getBookInfo(@NotNull(message = "图书aid不能为空") Integer aid ) {
        return bookManageService.getBookInfo(aid);
    }

    /**
     * 7、【新增/修改】获取图书类型
     *
     * @return ResponseWrapper
     */
    @GetMapping("/bookManage/getAllType")
    public ResponseWrapper getAllType() {
        return bookManageService.getAllType();
    }

    /**
     * 8.检验isbn号是否存在
     *
     * @param param CheckIsbnParam类
     * @return isbnResult
     */
    @GetMapping("/bookManage/checkIsbn")
    public ResponseWrapper checkIsbn(@Validated CheckISBNParam param) {
        return bookManageService.checkIsbn(param);
    }

    /**
     * 9.新增/修改图书信息
     *
     * @param param SaveBookParam类
     * @author: fzg
     * @date 2021.1.23 18:00
     */
    @PostMapping("/bookManage/saveBook")
    public ResponseWrapper saveBook(@RequestBody @Validated SaveBookParam param) {
        return bookManageService.saveBook(param);
    }


}
